home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / snip0493.zip / FORMAT.C < prev    next >
C/C++ Source or Header  |  1993-04-05  |  1KB  |  57 lines

  1. /*
  2. **  FORMAT.C - Use DOS FORMAT to format a diskette
  3. **
  4. **  Original Copyright 1992 by Bob Stout as part of
  5. **  the MicroFirm Function Library (MFL)
  6. **
  7. **  This subset version is hereby donated to the public domain.
  8. */
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12.  
  13. enum {ERROR = -1, SUCCESS};
  14.  
  15. /*
  16. **  format
  17. **
  18. **  Formats a specified floppy disk with optional switches.
  19. **
  20. **  Parameters: 1 - Drive letter ('A', 'B', ...) to format
  21. **              2 - Formatting switches in FORMAT.COM format, e.g. "/4"
  22. **              3 - Volume label
  23. **
  24. **  Returns: SUCCESS or ERROR
  25. */
  26.  
  27. int format(char drive, char *switches, char *vlabel)
  28. {
  29.       char command[128], fname[13];
  30.       FILE *tmpfile;
  31.  
  32.       tmpnam(fname);
  33.       if (NULL == (tmpfile = fopen(fname, "w")))
  34.             return ERROR;                       /* Can't open temp file */
  35.       fprintf(tmpfile, "\n%s\nN\n", vlabel);
  36.       fclose(tmpfile);
  37.  
  38.       sprintf(command, "format %c: /V %s < %s > NUL", drive, switches, fname);
  39.  
  40.       system(command);
  41.  
  42.       remove(fname);
  43.  
  44.       return SUCCESS;
  45. }
  46.  
  47. #ifdef TEST
  48.  
  49. void main(void)
  50. {
  51.       int retval = format((char)'a', "/4", "dummy_test");
  52.  
  53.       printf("format() returned %d\n", retval);
  54. }
  55.  
  56. #endif
  57.